﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Configuration;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    public class BooPentagon:BooTextShapesBase
    {
        Shapes.Polygon pentagon;
        public Shapes.Polygon Pentagon 
        {
            get 
            {
                return pentagon;
            }
            set
            {
                pentagon = value;
            }
        }

        BooPentagonElement pentagonElement;
        public BooPentagonElement PentagonElement 
        {
            get { return pentagonElement; }
        }

        public override BooElement Element
        {
            set { pentagonElement = (BooPentagonElement)value; }
            get { return pentagonElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return pentagonElement; }
        }

        public override Shapes.Shape Shape
        {
            get { return pentagon; }
        }


        public BooPentagon(BooPentagonElement pentagonElement, SaveForRedoUndo saveForRedoUndo)
            : base(pentagonElement)
        {
            this.pentagonElement = pentagonElement;
            InitOriginal();
            base.saveForRedoUndo = saveForRedoUndo;
            Focus.InitFocusEvent(this);
        }

        public BooPentagon(BooPentagonElement squareElement)
            : base(squareElement)
        {
            this.pentagonElement = squareElement;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            pentagon = new Shapes.Polygon();
            pentagon.Points = BooShapesPoints.CopyPointCollection(this.pentagonElement.Points);
            pentagon.ManipulationMode = ManipulationModes.All;
        }

        public override void ReSizeUI(double x, double y)
        {
            if (pentagonElement.ElementTransform.Width + x < 50 || pentagonElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            pentagonElement.ElementTransform.Width = pentagonElement.ElementTransform.Width + x;
            pentagonElement.ElementTransform.Height = pentagonElement.ElementTransform.Height + y;

            pentagonElement.PropertyChanged("Shape");
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }

        public override void ApplySize()
        {
            base.ApplySize();
            pentagonElement.ShapeWidth = pentagonElement.ElementTransform.Width;
            pentagonElement.ShapeHeight = pentagonElement.ElementTransform.Height;

            //this.pentagon.Width = pentagonElement.ElementTransform.Width;
           // this.pentagon.Height = pentagonElement.ElementTransform.Height;

            FullGrid.Width = pentagonElement.ElementTransform.Width;
            FullGrid.Height = pentagonElement.ElementTransform.Height;

            //BooCanvas.Width = pentagonElement.ElementTransform.Width;
           // BooCanvas.Height = pentagonElement.ElementTransform.Height;

            CenterStack.Width = pentagonElement.ElementTransform.Width;
            //CenterStack.MaxHeight = pentagonElement.ElementTransform.Height;


            this.TextBox.Width = pentagonElement.ElementTransform.Width;
            pentagonElement.TextWidth = pentagonElement.ElementTransform.Width;
            //this.TextBox.MaxHeight = pentagonElement.ElementTransform.Height;
            //pentagonElement.TextMaxHeight = pentagonElement.ElementTransform.Height;


            Focus.FocusElls.ScopeRectangle.Width = pentagonElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = pentagonElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(pentagonElement.ElementTransform.Width, pentagonElement.ElementTransform.Height);

            Point[] pt = new Point[pentagonElement.Points.Count];
            PointCollection pts = new PointCollection();
            pentagonElement.Points.CopyTo(pt, 0);
            pt[0].X = pentagonElement.ElementTransform.Width / 2;
            pt[0].Y = 0;
            pt[1].X = pentagonElement.ElementTransform.Width;
            pt[1].Y = pentagonElement.ElementTransform.Height * 0.4;
            pt[2].X = pentagonElement.ElementTransform.Width * 0.8;
            pt[2].Y = pentagonElement.ElementTransform.Height;
            pt[3].Y = pentagonElement.ElementTransform.Height;
            pt[3].X = pentagonElement.ElementTransform.Width * 0.2;
            pt[4].X = 0;
            pt[4].Y = pentagonElement.ElementTransform.Height * 0.4;
            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            pts.Add(pt[3]);
            pts.Add(pt[4]);
            pentagon.Points = pts;
            pentagonElement.Points = pts;
        }
    }
}
